package com.colorfruit.admin.pojo.enums;

import java.util.HashMap;
import java.util.Map;

public enum StatusEnum {

    EFFECTIVE_STATUS((byte)1, "有效"),

    CANCELLATION_STATUS((byte)9, "废弃")
    ;

    private byte statusCode;

    private String statusName;

    private volatile static Map<Byte, StatusEnum> mapping = null;


    StatusEnum(byte statusCode, String statusName) {
        this.statusCode = statusCode;
        this.statusName = statusName;
    }

    public static StatusEnum getStatusByCode(byte code) {
        if (mapping == null) {
            synchronized (StatusEnum.class) {
                if (mapping == null) {
                    mapping = new HashMap<>();
                    for (StatusEnum statusEnum : StatusEnum.values()) {
                        mapping.put(statusEnum.statusCode, statusEnum);
                    }
                }
            }
        }
        return mapping.get(code);
    }

    public byte getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(byte statusCode) {
        this.statusCode = statusCode;
    }

    public String getStatusName() {
        return statusName;
    }

    public void setStatusName(String statusName) {
        this.statusName = statusName;
    }
}
